﻿using Abp.Application.Services.Dto;
using Abp.Web.Mvc.Authorization;
using Akso.Authorization;
using Akso.Vendors;
using Akso.Vendors.Dto;
using Akso.Web.Areas.BasicData.Models.Vendors;
using Akso.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Akso.Web.Areas.BasicData.Controllers
{

    public class VendorsController : AbpZeroTemplateControllerBase
    {
        private readonly IVendorAppService _vendorsAppService;

        public VendorsController(IVendorAppService vendorsAppService)
        {
            _vendorsAppService = vendorsAppService;
        }

        /// <summary>
        /// 默认页面，只传查询对象，不做数据处理。
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var model = new VendorsViewModel
            {
                FilterText = Request.QueryString["filterText"]
            };
            return View(model);
        }


        /// <summary>
        /// 为新增、编辑数据页面加载数据，弹出修改页面框。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_BasicData_Vendors_Create, AppPermissions.Pages_BasicData_Vendors_Edit)]
        public async Task<PartialViewResult> CreateOrEditModal(Guid? id)
        {
            var output = await _vendorsAppService.GetObjectForEdit(new NullableIdInput<Guid> { Id = id });
            var viewModel = new CreateOrEditVendorModalViewModel(output);

            return PartialView("_CreateOrEditModal", viewModel);
        }
    }
}